<?php
	class newsControl extends Control{
		function index(){
			$db=M('news');
    		$count=$db->count();
    		$page=new page($count,8);
    		$row=$db->order('addtime desc')->findall($page->limit());
    		$this->assign('row',$row);
    		$this->assign('page',$page->show(2));
			$this->display();
		}
		function addshow(){
			// $db=M("channel");
			// $sql="select cid,cname,pid,concat(path,'_',cid)as p from hd_channel order by p";
			// $channel=$db->query($sql);
			// foreach($channel as $k=>$v){
			// 	$count=count(explode("_",$v['p']))-2;
			// 	$channel[$k]['html']=str_repeat("-", $count*2);
			// }
			// $this->assign('channel',$channel);
			// $flag=$db->table('flag')->all();
			// $this->assign('flag',$flag);
			$this->display();
		}
		function add(){
			//$db=K("newsRelation");
			$db=M("news");
			$_POST['addtime']=time();
			$_POST['author']=$_SESSION['uname'];
			if($db->add()){
				$this->success("添加成功",'index');
			}else{
				$this->success("添加失败");
			}
		}
		function updateShow(){
			$nid=$_GET['nid'];
			$db=M('news');
			$row=$db->find($nid);
			$this->assign('row',$row);
			$this->display();
		}
		function update(){
			$db=M('news');
			$_POST['addtime']=time();
			$_POST['author']=$_SESSION['uname'];
			$db->update();
			go(__CONTROL__);
		}
		function del(){
			$db=M('news');
			$nid=$_GET['nid'];
			$db->del($nid);
			go(__CONTROL__);
		}
		function show(){
			$db=M('news');
			$nid=$_GET['nid'];
			$row=$db->find($nid);
			$this->assign('row',$row);
			$this->display();
		}
	}
?>